package org.tony.spider.core.cmd;

import java.lang.reflect.Method;

import org.tony.spider.core.entries.Command;

public class RemoveCommandInvoker
    implements Invoker
{
  Boolean initial = false;
  Method  select  = null;
  Method  remove  = null;

  public Object invoke(Command cmd, Object target) throws Exception
  {
    synchronized (initial)
    {
      if (select == null)
      {
        select = target.getClass().getMethod("select", String.class);
      }
      if (remove == null)
      {
        remove = target.getClass().getMethod("remove");

      }
    }

    for (String lab : cmd.getLables())
    {
      remove.invoke(select.invoke(target, lab));
    }
    return target;
  }
}
